/**
 * $Revision: 1.0 $
 * $Author: Geln Yang $
 * $Date: Jul 17, 2010 10:38:56 AM $
 *
 * Author: Geln Yang
 * Date  : Jul 17, 2010 10:38:56 AM
 *
 */
package com.gooex.domain.common;

import java.io.Serializable;
import org.c4j.string.StringTools;

/**
 * @author Geln Yang
 * @version 1.0
 */
public class Subscription implements Serializable {

	/** the email to subscribe */
	private String email;

	/** the category of the subscription content */
	private String category;

	/**
	 * subscription interval
	 * <li>1: everyday</li>
	 * <li>1/7: every monday</li>
	 * <li>1/31: every first day for all month</li>
	 */
	private String interval;

	private boolean confirmed;

	private String confirmKey;

	public String getIntervalText() {
		if (StringTools.isBlankOrNull(interval) || "1".equals(interval))
			return "subscription.interval.everyday";
		String[] arr = interval.split("/");
		if (arr.length != 2)
			return "subscription.interval.everyday";
		try {
			int day = Integer.parseInt(arr[0]);
			int type = Integer.parseInt(arr[1]);
			if (type != 7 && type != 31)
				return "subscription.interval.everyday";
			else if (type == 7 && day <= 7)
				return "subscription.interval.week." + day;
			else if (type == 31 && day <= 31)
				return "subscription.interval.month." + day;
		} catch (Exception e) {
		}
		return "subscription.interval.everyday";
	}

	public String getInterval() {
		return interval;
	}

	public void setInterval(String interval) {
		this.interval = interval;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getConfirmKey() {
		return confirmKey;
	}

	public void setConfirmKey(String confirmKey) {
		this.confirmKey = confirmKey;
	}

	public boolean isConfirmed() {
		return confirmed;
	}

	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}
}
